/*
 Copyright (c) 2000-2001, Neil Rhodes and Julie McKeehan
    neil@pobox.com
 All rights reserved.

From the book "Palm Programming, the Developer's Guide, 2nd edition"
by O'Reilly.

Permission granted to use this file however you see fit.
*/

#define DO_NOT_ALLOW_ACCESS_TO_INTERNALS_OF_STRUCTS
#include <BuildDefines.h>
#ifdef DEBUG_BUILD
#define ERROR_CHECK_LEVEL ERROR_CHECK_FULL
#endif
#include <PalmOS.h>
#include "Utils.h"
#include "ResourceDefines.h"



Err RomVersionCompatible(UInt32 requiredVersion, UInt16 launchFlags)
{
  UInt32 romVersion;

  // See if we're on in minimum required version of the ROM or later.
  FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
  if (romVersion < requiredVersion) {
    UInt16 safeToCallAlertFlags;
    
    safeToCallAlertFlags = 
      sysAppLaunchFlagNewGlobals | sysAppLaunchFlagUIApp;
    if ((launchFlags & (safeToCallAlertFlags)) == safeToCallAlertFlags) {
      FrmAlert (RomIncompatibleAlert);
    
      // Pilot 1.0 will continuously relaunch this app unless we switch to 
      // another safe one.
      if (romVersion < sysMakeROMVersion(2,0,0,sysROMStageRelease,0))
        AppLaunchWithCommand(sysFileCDefaultApp, 
          sysAppLaunchCmdNormalLaunch, NULL);
    }
    
    return (sysErrRomIncompatible);
  }

  return errNone;
}


void *GetObjectPtr(FormPtr form, UInt16 objectID)
{
  return FrmGetObjectPtr(form, FrmGetObjectIndex(form, objectID));
}

void *GetObjectPtrFromActiveForm(UInt16 objectID)
{
  return GetObjectPtr(FrmGetActiveForm(), objectID);
}

